package voidgame.core;
public class Player{
	
	int[] pos;
	int orientation;
	Ship ship;
	StarSystem starSystem;
	Game game;
	int movePoints;
	
	public Player(Game g){
		game =g;
		starSystem = g.galaxy.systems.get(g.galaxy.systems.size()-1);
		ship = new Ship();
		pos = new int[2];
		pos[0]=20;
		pos[1]=13;
		orientation=1;
		
		movePoints = new Double(Math.ceil(ship.speed/10)).intValue();
	}
	
	public void move(int dir){
		orientation=dir;
		if(movePoints>0){
			switch(dir){
				case 0:{
					if(moveCheck(0, pos[0]-1))
						pos[0]--;
					break;
				}
				case 1:{
					if(moveCheck(1, pos[1]-1))
						pos[1]--;
					break;
				}
				case 2:{
					if(moveCheck(0, pos[0]+1))
						pos[0]++;
					break;
				}
				case 3:{
					if(moveCheck(1, pos[1]+1))
						pos[1]++;
					break;
				}
			}
			movePoints--;
		}
	}
	
	public boolean moveCheck(int axis, int val){
		boolean res = true;
		
		switch(axis){
			case 0:{
				if(val<0||val>54)
					res=false;
				break;
			}
			case 1:{
				if(val<0||val>24)
					res=false;
				break;
			}
		}

		return res;
	}
	
	public void enterWormHole(){
		if(starSystem.map[pos[0]][pos[1]].type==4){
			Wormhole w = (Wormhole)starSystem.map[pos[0]][pos[1]].obj;
			if(starSystem==w.alpha){
				starSystem=w.beta;
				pos[0]=w.betaPos[0];
				pos[1]=w.betaPos[1];
			}
			else{
				starSystem=w.alpha;
				pos[0]=w.alphaPos[0];
				pos[1]=w.alphaPos[1];
			}
			
		}
	}
	
	public void endTurn(){
		movePoints = new Double(Math.ceil(ship.speed/10)).intValue();
	}
	
}